import {useEffect, useState} from "react";
import {DetailProps, fetchGetDetail} from "@/api/Detail.ts";
import {useSearchParams} from "react-router-dom";

function useDetail() {
    const [DetailList, setDetailList] = useState<DetailProps | null>(null)
// 获取路由参数
    const [searchParams] = useSearchParams()
// @ts-ignore
    const id = searchParams.get("id")
    useEffect(() => {
        const getDetail = async () => {
            try {
                const res = await fetchGetDetail(id!)
                setDetailList(res.data.data)
            } catch (e) {
                throw new Error("获取详情失败")
            }
        }
        getDetail()
    }, [id]);

    return {
        DetailList
    }
}

export default useDetail